package com.sunxiansheng.designPattern.template;


import com.sunxiansheng.response.Result;

/**
 * Description: api模板
 * @Author sun
 * @Create 2024/7/22 10:17
 * @Version 1.0
 */
public class ApiTemplate {

    /**
     * 执行方法聚合Action的不同对象逻辑，从而实现模板的动态变化
     * @param result
     * @param action
     */
    public void execute(Result result, final Action action) {
        try {
            action.validate();
            action.execute();
            action.after();
            result.setSuccess(true);
            result.setCode(200);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setCode(500);
        }
    }

}